import { createRouter, createWebHistory } from 'vue-router'
import { useUserStore } from '../stores/user'

const router = createRouter({
    history: createWebHistory(),
    routes: [
        {
            path: '/login',
            name: 'Login',
            component: () => import('../views/LoginView.vue')
        },
        {
            path: '/',
            component: () => import('../layouts/MainLayout.vue'),
            meta: { requiresAuth: true },
            children: [
                {
                    path: '',
                    redirect: '/dashboard'
                },
                {
                    path: 'dashboard',
                    name: 'Dashboard',
                    component: () => import('../views/DashboardView.vue')
                },
                {
                    path: 'entries',
                    name: 'Entries',
                    component: () => import('../views/EntriesView.vue')
                },
                {
                    path: 'statistics',
                    name: 'Statistics',
                    component: () => import('../views/StatisticsView.vue')
                },
                {
                    path: 'settings',
                    name: 'Settings',
                    component: () => import('../views/SettingsView.vue')
                },
                {
                    path: 'profile',
                    name: 'Profile',
                    component: () => import('../views/UserProfileView.vue')
                },
                {
                    path: 'competitions',
                    name: 'Competitions',
                    component: () => import('../views/CompetitionsView.vue')
                },
                {
                    path: 'notifications',
                    name: 'Notifications',
                    component: () => import('../views/NotificationsView.vue')
                },
                {
                    path: 'data-analysis',
                    name: 'DataAnalysis',
                    component: () => import('../views/DataAnalysisView.vue')
                },
                {
                    path: 'reports',
                    name: 'Reports',
                    component: () => import('../views/ReportsView.vue')
                },
                {
                    path: 'user-management',
                    name: 'UserManagement',
                    component: () => import('../views/UsersView.vue')
                },
                {
                    path: 'system-logs',
                    name: 'SystemLogs',
                    component: () => import('../views/LogsView.vue')
                },
                {
                    path: 'system-monitor',
                    name: 'SystemMonitor',
                    component: () => import('../views/MonitorView.vue')
                },
                {
                    path: 'registration-flow',
                    name: 'RegistrationFlow',
                    component: () => import('../views/RegistrationFlowView.vue')
                },
                {
                    path: 'payment',
                    name: 'Payment',
                    component: () => import('../views/PaymentView.vue')
                }
            ]
        }
    ]
})

router.beforeEach((to, from, next) => {
    const userStore = useUserStore()

    if (to.meta.requiresAuth && !userStore.isAuthenticated) {
        next('/login')
    } else {
        next()
    }
})

export default router 